import json


def block_chain_to_json(block_chain):
    temp = list()
    for item in block_chain:
        cover = block_to_json(item)
        temp.append(cover)
    return json.dumps(temp)


def block_to_json(block):
    cover = dict()
    cover['index'] = block.index
    cover['previous_hash'] = block.previous_hash
    cover['timestamp'] = block.timestamp
    cover['data'] = block.data
    cover['data_hash'] = block.data_hash
    cover['bits'] = block.bits
    cover['nonce'] = block.nonce
    cover['nonce'] = block.nonce
    cover['miner_ip'] = block.miner_ip
    return cover
